package net.lanelife.casino.cms.web.controller;

import net.lanelife.casino.caipiao.dto.admin.CompanyBankCardCreateDTO;
import net.lanelife.casino.caipiao.dto.admin.CompanyBankCardDTO;
import net.lanelife.casino.caipiao.dto.admin.CompanyBankCardTable;
import net.lanelife.casino.caipiao.dto.admin.CompanyBankCardUpdateDTO;
import net.lanelife.casino.caipiao.entity.CompanyBankCard;
import net.lanelife.casino.caipiao.service.api.IBankService;
import net.lanelife.casino.caipiao.service.api.ICompanyBankCardService;
import net.lanelife.casino.cms.web.controller.support.CRUDController;
import net.lanelife.casino.common.service.support.IGenericService;
import net.lanelife.casino.common.web.resolver.ViewResolver;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

@Controller
@RequestMapping(value = CompanyBankCardController.PATH)
public class CompanyBankCardController extends CRUDController<CompanyBankCard, Integer, CompanyBankCardDTO, CompanyBankCardCreateDTO, CompanyBankCardUpdateDTO, CompanyBankCardTable<CompanyBankCardDTO>> {
	
	public static final String PATH = "/company-bank-card";
	
	public CompanyBankCardController() {
		super(PATH);
	}

	@Autowired
	private ICompanyBankCardService companyBankCardService;
	
	@Autowired
	private IBankService bankService;
	
	@Override
	protected IGenericService<CompanyBankCard, Integer> getService() {
		return companyBankCardService;
	}
	
	@Override
	protected void preCreate(Model model, CompanyBankCardCreateDTO createDTO) throws Exception {
		model.addAttribute("bankList", bankService.findAll());
	}

	@Override
	protected void preUpdate(Model model, CompanyBankCardUpdateDTO updateDTO) throws Exception {
		model.addAttribute("bankList", bankService.findAll());
	}

	
	@RequestMapping(value = { "/available:{available}/{id}" }, method = RequestMethod.GET)
	public String available(@PathVariable Integer id, @PathVariable Boolean available) throws Exception {
		companyBankCardService.update(id, available);
		return ViewResolver.getView(PATH + "/list");
	}
	

}
